﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Slaks.Graphs.Analysis.ClusteringMeasures
{
    public class AvgPrecision : ClusteringMeasureBase
    {
        public override object evaluate(GraphList[] clusters, Slaks.Graphs.Category.CategoriesFile categoriesFile)
        {
            double precisionSum = 0d;
            int totalCount = 0;
            foreach (GraphList cluster in clusters)
            {
                var clusterPrecision = IRAnalysis.GetClusterPrecision(cluster, categoriesFile);
                precisionSum += clusterPrecision * cluster.Count;
                totalCount += cluster.Count;
            }
            return totalCount == 0 ? 0 : precisionSum / totalCount;
        }

        public override string getMeasureName()
        {
            return "AvgPrecision";
        }
    }
}
